//
//  ITBaseAlertView.m
//  Water
//
//  Created by seven on 2020/8/5.
//  Copyright © 2020 seven. All rights reserved.
//

#import "ITBaseAlertView.h"

@implementation ITBaseAlertView

+ (instancetype)showWithinfo:(NSMutableDictionary *)info action:(CustomAction)action{
    return [self showInView:nil frame:CGRectZero withinfo:info action:action];
}

+ (instancetype)showInView:(UIView *)view frame:(CGRect)frame withinfo:(NSMutableDictionary *)info action:(CustomAction)action{
    ITBaseAlertView *tip = [self showInView:view frame:frame withAction:action];
    tip.resultInfo = info;
    return tip;
}


- (void)initViews{
    [super initViews];
    
    self.backgroundColor = ColorWithHexAplha(0x000000, 0.8);
    
    _contentView = [BaseView initWithFrame:CGRectMake(22, 0, self.width-44, 0)];
    _contentView.backgroundColor = ColorWithHex(0xFFFFFF);
    [_contentView setCornerRadius:4];
    [self addSubview:_contentView];
    
    _titleLbl = [BaseLabel initWithFrame:CGRectMake(22, 24, _contentView.width-44, 30)];
    _titleLbl.font = SemiboldFontWithSize(22);
    _titleLbl.textColor = COLOR_333333;
    [_contentView addSubview:_titleLbl];
    
    _closeBtn = [UIButton initWithFrame:CGRectMake(0, 0, 54, 54)];
    [_closeBtn setImageWithName:@"check_close"];
    [_closeBtn addTarget:self action:@selector(onCloseAction)];
    [self addSubview:_closeBtn];
    _closeBtn.alpha = 0;
    [_closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(54, 54));
        make.centerX.equalTo(_contentView.mas_trailing);
        make.centerY.equalTo(_contentView.mas_top);
    }];
    
    _okBtn = [UIButton initWithFrame:CGRectMake((_contentView.width-176)/2, 0, 176, 46)];
    [_okBtn setCornerRadius:_okBtn.height/2];
    _okBtn.backgroundColor = COLOR_CUSTOM_YELLOW;
    _okBtn.titleLabel.font = SemiboldFontWithSize(16);
    [_okBtn setTitleColor:COLOR_333333];
    [_okBtn setTitleNormal:LocalTitle(@"OK")];
    [_okBtn addTarget:self action:@selector(onDoneAction)];
    [_contentView addSubview:_okBtn];
}

- (void)setResultInfo:(NSMutableDictionary *)resultInfo{
    _resultInfo = resultInfo;
    [self updateViews];
}

- (void)updateViews{
    
}

- (void)setCloseBtnHidden:(BOOL)hidden{
    _closeBtn.hidden = hidden;
    _okBtn.userInteractionEnabled = !hidden;
    
    [_closeBtn fadeAnimation];
}

- (void)setupHeight{
    //self.contentHeight = 251;
}


- (void)setContentHeight:(CGFloat)contentHeight{
    _contentHeight = contentHeight;
    CGRect rect = _contentView.frame;
    rect.size.height = _contentHeight;
    rect.origin.y = (self.height-_contentHeight)/2;
    _contentView.frame = rect;
    
    _okBtn.bottom = contentHeight-30;
    
    _closeBtn.alpha = 1;
}

- (void)setTitle:(NSString *)title{
    _title = title;
    _titleLbl.text = title;
}

- (void)onCloseAction{
    if (self.customAction) {
        self.customAction(self, cat_close);
    }
    [self hideAnimation];
}

- (void)onDoneAction{
    [self _onDoneAction];
}

- (void)_onDoneAction{
    if (self.customAction) {
        self.customAction(self, cat_done);
    }
    [self hideAnimation];
}



@end
